package top.healthylife.gateway.platform.geo.api.config;


import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import top.healthylife.gateway.core.config.BaseConfig;
import top.healthylife.gateway.dto.annotation.SystemInfo;
import top.healthylife.gateway.dto.annotation.SystemInfoField;

import java.io.Serializable;
import java.util.UUID;

/**
 * @author cl
 * @version 1.0
 * @date 2020/4/10 17:48
 */
@SystemInfo(systemName = "集奥", shortName = "geo")
@Data
@Configuration
@Accessors(chain = true)
@ConfigurationProperties(prefix = "system")
public class SystemConfig extends BaseConfig implements Serializable {
    private static final long serialVersionUID = -4735148160159528848L;
    /**
     * 账户向GEO申请开通
     */
    @SystemInfoField(value = "账户名")
    private String username;

    @SystemInfoField(value = "密码")
    private String password;

    @SystemInfoField(value = "客户编号")
    private String uno;
    /**
     * AES(秘钥长度不固定)、DES(秘钥长度8)、DESede(秘钥长度24)
     */
    private String encryptionType = "AES";
    /**
     * 加密类型和加密秘钥向GEO索取(如果是获取数据的时候传的是RSA那么这里自己定义即可)
     */
    @SystemInfoField(value = "加密Key,默认采用AES加密")
    private String encryptionKey ;

    /**
     * 获取token的时候传递的参数加密类型
     */
    private String etype = "RSA";

    /**
     * 是否加密传输
     */
    private Integer encrypted = 1;

    /**
     * 不使用证书加密
     */
    private Integer dsign = 0;

    private String tokenId;

    private String authCode;

    /**
     * 处理授权码
     */
    public String getAuthCode() {
        long time = System.currentTimeMillis() / 1000;
        // 该处为示意，应该为能关联上用户授权信息的ID左补全成32位
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        // 授权码得对应上客户合同编号
        String unoFormat = this.uno;
        return time + unoFormat + uuid;
    }

    public void setUno(String uno) {
        this.uno = "00" + uno;
    }
}
